package com.pengtu.gsj.controller.gcjs;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.gcjs.YHRoadConstructionB;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.gcjs.YHRoadConstructionBService;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

@Controller
@RequestMapping("yHRoadConb")
public class YHRoadConstructionBController extends DefaultBaseController {
	
	@Autowired
	private YHRoadConstructionBService yHRoadConstructionBService;
	
	/**
	 * 
	 * getYHRoadConstructionBs:
	 * 适用:按属性要求获取码表列表
	 * @param page 对象集
	 * @param request
	 * @param model 传递参数
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "list", produces = "application/json; charset=utf-8")
	@ResponseBody
	public Page<YHRoadConstructionB> getYHRoadConstructionBs(Page<YHRoadConstructionB> page,HttpServletRequest request) {
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("year");
			page.setOrder(Page.ASC);
		}
		page = yHRoadConstructionBService.findYHRoadConstructionBs(page, queryFilter);
		return page;
	}
	
	/**
	 * 
	 * loadEntity:
	 * 适用: 每个方法执行之前都会执行该方法
	 * @param id  YHRoadConstructionB主键id
	 * @return 返回持久对象YHRoadConstructionB或者新创建对象
	 * @exception 
	 * @since  1.0.0
	 */
	@ModelAttribute
	public YHRoadConstructionB loadEntity(String id){
		YHRoadConstructionB yHRoadConstructionB ;
		if (StringUtils.isNotEmpty(id)) {
			yHRoadConstructionB = yHRoadConstructionBService.getYHRoadConstructionB(id);
		}else {
			yHRoadConstructionB = new YHRoadConstructionB();
		}
		return yHRoadConstructionB;
	}
	
	/**
	 * 
	 * saveYHRoadConstructionB:保存对象
	 * 适用:
	 * @param YHRoadConstructionB 对象
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveYHRoadConstructionB(@ModelAttribute YHRoadConstructionB yHRoadConstructionB) {
		yHRoadConstructionBService.saveYHRoadConstructionB(yHRoadConstructionB);
		return true;
	}
	
	
	/**
	 * 
	 * deleteYHRoadConstructionB:删除对象
	 * 适用:
	 * @param id
	 * @param attributes
	 * @return 删除是否成功
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean deleteYHRoadConstructionB(String id){
		yHRoadConstructionBService.deleteYHRoadConstructionB(id);
		return true;
	}

	
	/**
	 * 
	 * showYHRoadConstructionB:修改对象
	 * 适用:
	 * @param YHRoadConstructionB 对象
	 * @return 对象
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="show")
	@ResponseBody
	public YHRoadConstructionB showYHRoadConstructionB(@ModelAttribute YHRoadConstructionB yHRoadConstructionB){
		return yHRoadConstructionB;
	}
	
	
	/**
	 * 
	 * showYHRoadConstructionBList:返回列表页面
	 * 适用:
	 * @param page
	 * @param request
	 * @param model
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showYHRoadConstructionBList(HttpServletRequest request) {
		return "gcjs/yHRoadConbList";
	}

	/**
	 * checkYear:
	 * 适用:验证路面硬化的年份唯一
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping(value="checkYear", produces="application/json;charset=utf-8")
	public Boolean checkYear(){
		String year = SpringMvcUtils.getParameter("year");
		String id = SpringMvcUtils.getParameter("id");
		return yHRoadConstructionBService.checkYear(year, id);
	}
}
